/*
-----------------------------------------------------------------------------
This file is part of NxGraphics, Multimedia Engine.
Author : Stephane Kyles. Developed in Prague, Czech Republic.
				_   __      _    __ _      __           
			   / | / /_  __| |  / /(_)____/ /___   ____ 
			  /  |/ /| |/_/| | / // // __  // _ \ / __ \
			 / /|  /_>  <  | |/ // // /_/ //  __// /_/ /
			/_/ |_//_/|_|  |___//_/ \__,_/ \___/ \____/ 

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __NXVIDEOPLAYER_H__
#define __NXVIDEOPLAYER_H__
 
#include "NxVideo_Prerequisites.h"

namespace NxVideo_Namespace {

class NxVideo_Export NxVideoPlayerListener
{
	public :
	virtual ~NxVideoPlayerListener(){};
	virtual void NxVideoPlayerUpdated( unsigned long FrameNb ){};
};

//!  A Class To Play Video Files / Avi / MOV / SWF / FLV / WEB.
/*!
	NxVideo_Player Class Implementation.
*/
class NxVideo_Export NxVideo_Player
{
	public : 
	//! NxVideo_Player Class Constructor.
	NxVideo_Player();
	//! NxVideo_Player Class Deconstructor.
	~NxVideo_Player();
	//! Open File With Specified Parameters.
	virtual bool OpenVideoFile( const std::string& FilePath );
	//! Close Video File.
	virtual bool CloseVideoFile();
	//! Render a Frame.
	virtual bool RenderFrame();
	//! Get Pixel Buffer Data.
	virtual BYTE * GetPixelData();
	//! Set Video Framerate.
	void SetFramerate( float framerate );
	//! Get Video Framerate.
	float GetFramerate();
	//! Play Video.
	virtual void Play();
	//! Pause Video;
	virtual void Pause();
	//! Stop Video.
	virtual void Stop();
	//! Rewind And Play Video.
	virtual void Rewind();
	//! Set Video Position.
	virtual void SeekPosition( unsigned long Frame );
	//! Get Video Current Position / Hour.
	unsigned int GetVideoHours();
	//! Get Video Current Position / Minutes.
	unsigned int GetVideoMinutes();
	//! Get Video Current Position / Seconds.
	unsigned int GetVideoSeconds();
	//! Get Video Width.
	unsigned long GetWidth();
	//! Get Video Height.
	unsigned long GetHeight();
	//! Get Video Bits Per Pixel.
	unsigned int GetBpp();
	//! Get Video Duration / Frames.	
	unsigned long GetVideoDurationframes();
	//! Get Video Codec Name.
	const std::string GetCodecName();
	//! Get Video Stream Type. see NxVideoStreamType.
	NxVideoStreamType GetType();
	//! Get Video Full Path.
	const std::string & GetVideoFullPath() const;
	//! Get Video Name.
	const std::string & GetVideoName() const;
	//! Get Video Extension.
	const std::string & GetVideoExtension() const;


	virtual void SetInboundFrame( unsigned long Frame );
	virtual unsigned long GetInboundFrame();
	virtual void SetOutboundFrame( unsigned long Frame );
	virtual unsigned long GetOutboundFrame();



	virtual bool NewFrame();
	virtual void ResetFrame();
 
	void SetManualUpdate( bool Manual );
	bool IsManualUpdate();

	void SetPlayBackType( NxVideo_PlayBack_Type type );
	NxVideo_PlayBack_Type GetPlayBackType();

	NxVideo_PlayBack_Status GetPlayBackState();
	void SetPlayBackState( NxVideo_PlayBack_Status Status );

	void StepFrame( unsigned long FrameNum );
	unsigned long GetPositionFrame();
	void StepTime( double TimePos );

	friend DWORD VideoUpdateThread( LPVOID lpParameter );
	void StartRendering();
	void StopRendering();

	std::list<NxVideoPlayerListener *> mListenersPlayerList;
	void AddListener( NxVideoPlayerListener * listener );
	void RemoveListener( NxVideoPlayerListener * listener );

	bool mVideoLoop;
	HANDLE mVideoLoopHandle;
	bool mNewFrame;

	bool mVideoSwitchBounce ;
	bool mVideoCheckBounce ;
	BYTE * mVideoData;
protected:

	unsigned long mVideoWidth;
	unsigned long mVideoHeight;
	int mVideoBpp;
	bool mManualUpdate ;
	unsigned long mFrameInbound;
	unsigned long mFrameOutbound;
	unsigned long mFrameOffset;
	unsigned long mFramesLength;
	unsigned long mFrame;
	unsigned long mFramePrevious;
	float mVideoFrameRate;
	std::string mVideoFullPath ;
	std::string mVideoFullName ;
	std::string mVideoExtension ;
	std::string mVideoCodecName;
	NxVideoStreamType mVideoType ;

	NxVideo_PlayBack_Type mVideoPlayType;
	NxVideo_PlayBack_Type mVideoPlayTypePrevious;
	NxVideo_PlayBack_Status mVideoPlayState;
	
};


//!  A Class To Record Video Files / Avi / MOV.
/*!
	NxVideo_Recorder Class Implementation.
*/
class NxVideo_Export NxVideo_Recorder
{
public:
	NxVideo_Recorder();
	~NxVideo_Recorder();
};



class NxVideo_Export NxVideoPlayerPtr : public shared_ptr<NxVideo_Player> 
{
public:
	NxVideoPlayerPtr() : shared_ptr<NxVideo_Player>(){ }
    explicit NxVideoPlayerPtr( NxVideo_Player * rep ) : shared_ptr<NxVideo_Player>(rep){ }
    NxVideoPlayerPtr( const NxVideoPlayerPtr& r ) : shared_ptr<NxVideo_Player>(r){ } 
};




}

#endif